;

let li = document.getElementsByClassName("g")
let d = document.getElementsByClassName("d")
let box = document.getElementById("box")
let innerTexts = document.querySelectorAll(".innerText")
let nextPageTime = 5000
let index = 0
let showTime = 2000
//自动翻页
function toNext() {
    index++
    if (index > li.length - 1) {
        index = 0
    }
    for(let i = 0;i < innerTexts.length;i++) {
        innerTexts[i].style.transition = "0s"
        innerTexts[i].style.opacity = '0'
    }

    setTimeout(function (){
        innerTexts[index].style.transition = "0.5s"
        innerTexts[index].style.opacity = "1"
    },showTime-1200)
    for (let i = 0; i < li.length; i++) {
        li[i].style.zIndex = '0'
        li[i].style.transition = '0s'
        li[i].style.opacity = "0";
        d[i].style.background = "#ccc"
    }
    d[index].style.background = "#76B900"
    li[index].style.zIndex = `9999`
    li[index].style.transition = `${showTime/1000}s`
    li[index].style.opacity = "1"
}


//底部按钮
for (let i = 0; i < d.length; i++) {
    d[i].count = i
    d[i].onclick = function () {
        for (let i = 0; i < li.length; i++) {
            li[i].style.zIndex = '0'
            li[i].style.transition = '0s'
            li[i].style.opacity = "0"
            d[i].style.background = "#ccc"
        }
        for(let i = 0;i < innerTexts.length;i++){
            innerTexts[i].style.transition = "0s"
            innerTexts[i].style.opacity = '0'
        }
        setTimeout(()=>{
            innerTexts[this.count].style.transition = "0.5s"
            innerTexts[this.count].style.opacity = "1"
        },showTime-1200)
        li[this.count].style.zIndex = `9999`
        li[this.count].style.transition = `${showTime/1000}s`
        li[this.count].style.opacity = '1'
        this.style.background = "#76B900"
        index = this.count
    }
}

let timer = setInterval(toNext,nextPageTime)


box.onmouseover = function () {
    clearInterval(timer)
}
box.onmouseout = function () {
    //防止重复开启定时器
    clearInterval(timer)
    timer = setInterval(toNext,nextPageTime)
}